package com.ib.review.base.exception;

import com.ib.review.base.response.JsonResult;
import com.ib.review.base.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    // 定义处理业务层异常的方法
    @ExceptionHandler
    public JsonResult<Void> doHandleServiceException(ServiceException ex) {
        log.warn("业务层异常: {}", ex.getStatusCode().getMsg());
        return new JsonResult<>(ex.getStatusCode());
    }

    @ExceptionHandler
    public JsonResult<String> doHandleRuntimeException(RuntimeException ex) {
        String message = ex.getMessage();
        log.error("RuntimeException: {}", message);
        return new JsonResult<>(StatusCode.OPERATION_FAILED, message);
    }
}
